package state.pattern;

/**
 * @author ZLL
 * @date create in 2018/05/10
 */
public abstract class AccountState {

    protected Account account;

    protected void depoise(double amount){
        account.deposit(account.getBalance() + amount);

        stateCheck();
    }

    protected void withDraw(double amount){
        account.withDraw(account.getBalance() - amount);

        stateCheck();
    }

    protected void stateCheck(){
        if(account.getBalance() > 0){
            account.setState(new NormalState(this));
        }else if(account.getBalance() == -2000){
            account.setState(new RestrictedState(this));
        }else if(account.getBalance() < -2000){
            System.out.println("操作受限制。。。");
        }
    }

    abstract void computeInterest();
}
